package com.hfy.kandian.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hfy.kandian.dao.command.BaseCommand;
import com.hfy.kandian.dao.representation.TagRepresentation;
import com.hfy.kandian.entity.Tag;
import com.hfy.kandian.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HAN XIAOYANG
 * @since 2020-12-30
 */
@RestController
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagService tagService;

    @ApiOperation(value = "添加一个标签")
    @GetMapping("/add/{tagName}/{tagIntroduction}")
    public int addTag(@PathVariable String tagName,@PathVariable String tagIntroduction){
        return tagService.add(tagName,tagIntroduction);
    }

    @ApiOperation(value = "展示所有标签")
    @PostMapping("/all")
    public IPage<TagRepresentation> all(@RequestBody BaseCommand baseCommand){
        return tagService.all(baseCommand);
    }

    @ApiOperation(value = "根据ID删除指定标签")
    @GetMapping("/remove/{tagId}")
    public int remove(@PathVariable int tagId){
        return tagService.removeById(tagId)?1:0;
    }

    @ApiOperation(value = "依据ID修改指定标签")
    @GetMapping("/modify/{tagId}/{tagName}/{tagIntroduction}")
    public int modify( @PathVariable int tagId,@PathVariable String tagName,@PathVariable String tagIntroduction){
        return tagService.updateById(new Tag().setTagId(tagId).setTagName(tagName).setTagIntroduction(tagIntroduction))?1:0;
    }

}

